#pragma once
#include "Window.h"

template<class T>
class SingletonWindow : public Window
{
public:
	SingletonWindow() {}
	virtual ~SingletonWindow() {}

	static T& Instance();
	
	virtual void Close();
	virtual bool Open();

	static bool Exist();
	
private:
	SingletonWindow( const SingletonWindow& );
	SingletonWindow& operator =( const SingletonWindow& );
	
private:
	static T *ms_instance;
};

template <class T>
T* SingletonWindow<T>::ms_instance = NULL;

template <class T>
T& SingletonWindow< T >::Instance()
{
	if( !ms_instance )
		ms_instance = new T;

	return *ms_instance;
}

template <class T>
bool SingletonWindow<T>::Open()
{
	return Window::Open();
}

template <class T>
void SingletonWindow<T>::Close()
{
	if( ms_instance )
	{
		T* copy = ms_instance;
		ms_instance = NULL;
		copy->Destroy();
		SAFE_DELETE( copy );
	}
}

template <class T>
bool SingletonWindow<T>::Exist()
{
	return NULL != ms_instance;
}
